Ext.Loader.setConfig({enabled:true});
Ext.Loader.setPath('Ext.ux','/style/common/extjs4/ux');
Ext.Loader.setPath('channel', '/channel');
Ext.require([
    'Ext.ux.form.SearchField',
    'channel.common.ExecludePanel',
    'channel.common.ExecludeWin',
    'channel.common.LogList',
    'channel.common.MethodPanel',
    'channel.common.MethodWin',
    'channel.commodity.CommodityLogList',
    'channel.common.ExecludeWin',
    'channel.commodity.CommoditySnapPanel',
    'channel.commodity.CommoditySnapWin',
    'channel.commodity.CommoditySnapSearchWin',
    'channel.commodity.ExecludeCommodityPanel',
    'channel.commodity.ExecludeCommodityWin',
    'channel.commodity.CommodityTools'
    ]);

Ext.define('commodityExcludeTree', {  
    extend: 'Ext.data.Model',  
    fields: [  
        {name: 'id',  type: 'string'},  
        {name: 'text',  type: 'string'},
        {name: 'distribute',  type: 'integer'}
    ]
});
var westTreeStore = Ext.create('Ext.data.TreeStore', {
	model: 'commodityExcludeTree',  
	root : {  
        text: '渠道分类',
        distribute:"-99",
        expanded : true,  
        children : [ {
        	id : "1",
        	distribute:"-1",
            text : "所有渠道",  
            leaf : true  
        }, { 
        	id : "2",
        	distribute:"-99",
            text : "淘宝",  
            expanded : true,  
            children : [ {  
            	id : "3",
            	distribute:"110",
            	text : "淘宝商城",  
                leaf : true  
            },{  
            	id : "4",
            	distribute:"122",
            	text : "淘宝经管店",  
                leaf : true  
            },{  
            	id : "5",
            	distribute:"123",
            	text : "淘宝医学店",  
                leaf : true  
            }]  
        }, { 
        	id : "6",
        	distribute:"-99",
            text : "拍拍",  
            expanded : true,  
            children : [ {  
            	id : "7",
            	distribute:"111",
            	text : "拍拍商城",  
                leaf : true  
            } ]  
        }, { 
        	id : "8",
        	distribute:"-99",
            text : "新浪",  
            expanded : true,  
            children : [ {  
            	id : "9",
            	distribute:"112",
            	text : "新浪商城",  
                leaf : true  
            } ]  
        }, { 
        	id : "10",
        	distribute:"-99",
            text : "我有网",  
            expanded : true,  
            children : [ {  
            	id : "11",
            	distribute:"120",
            	text : "我有商城",  
                leaf : true  
            }]  
        } ]  
    }
});

Ext.define('channel.MainPanel',{
	extend:'Ext.container.Viewport',
	layout:'border',
	initComponent:function(){
		this.topPanel = Ext.create('Ext.Component',{
			region:'north',
			el:'header',
			border:false,
			margins:'1 0 2 0'
		});
		this.center = Ext.create('Ext.tab.Panel',{
			enableTabScroll:true,
			region:'center',
			activeTab:1,
			layout:'fit',
			items:[
//		       {xtype:'methodpanel',title:'功能管理'},
//		       {xtype:'execludepanel',title:'资源管理'},
		       {xtype:'commoditySnapPanel',title:'商品快照'},
		       {xtype:'execludecommoditypanel',title:'排除商品'},
		       {xtype:'commodityloglist',title:'日志查看'},
		       {xtype:'commoditytools',title:'查询工具'},
//		       {xtype:'loglist',title:'日志管理'}
		       ]
		});
		this.items = [this.center,this.topPanel];
		this.callParent();
		this.on('afterrender',function(){
			Ext.get('logout-link').on('click',function(){
				Ext.Msg.show({
					icon:Ext.Msg.QUESTION,
					buttons:Ext.Msg.YESNO,
					width:120,
					scope:this,
					msg:'退出系统?',
					fn:function(btn){
						if(btn=='yes'){
							channel.openLink({
								url	:'/member/logout.json',
								scope : this,
								masker : this,
								onSuccess : function(rs){
									Ext.Msg.alert('提示','退出成功，转向登录页面..');
									window.location.href='/member/login';
								}
							});
						}
					}
				})
			},this);
			setTimeout(function(){
				Ext.get("login-loading").remove();
				Ext.get("loading-mask").fadeOut({duration:1,remove:true});
			},100);
		},this);
	}
});


initMainPanel = function(){
	new channel.MainPanel();
}
